﻿using System.Net;
using Catchbase.TestTools;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;

namespace Catchbase.Service.API.UTest
{
    [TestClass]
    public class SecurityManagerTest
    {
        private WebHeaderCollection _headers;
        private Mock<HttpWebRequestGateway> _request;
        private SecurityManager _manager;

        [TestInitialize]
        public void InitializeTest()
        {
            _request = new Mock<HttpWebRequestGateway>();
            _headers = new WebHeaderCollection();
            _request.Setup(r => r.Headers).Returns(_headers);
            _manager = new SecurityManager("my@email.com", "pwd");
        }

        [TestMethod]
        public void SecureRequest_MustAddAuthorizationRequestHeader()
        {
            _manager.SecureRequest(_request.Object);
            _headers.Get("Authorization").MustNotBeNull();
        }

        [TestMethod]
        public void SecureRequest_MustBe()
        {
            _manager.SecureRequest(_request.Object);
            _headers.Get("Authorization").MustEqual("Basic bXlAZW1haWwuY29tOnB3ZA==");
            _manager = new SecurityManager("my.other@email.com", "pwd");
            _manager.SecureRequest(_request.Object);
            _headers.Get("Authorization").MustEqual("Basic bXkub3RoZXJAZW1haWwuY29tOnB3ZA==");
        }

    }
}